package com.iwhalecloud.bss.kite.cucc.service.spec.query;

import com.iwhalecloud.bss.kite.client.api.spec.query.IQueryServiceOfferSpecService;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.dto.inst.ServiceOfferDTO;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryServiceOfferService;
import com.iwhalecloud.bss.kite.dataservice.entity.ServiceOffer;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class QueryServiceOfferSpecService implements IQueryServiceOfferSpecService {

    @Autowired
    private IQueryServiceOfferService queryServiceOfferService;

    @Override
    public DataResult<List<ServiceOfferDTO>> listServiceOffer() {
        List<ServiceOffer> serviceOfferList = queryServiceOfferService.qryAllServiceOffer();
        if (CollectionUtils.isNotEmpty(serviceOfferList)) {
            return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(serviceOfferList, ServiceOfferDTO.class));
        }
        return ErrorConsts.SUCCESS.getResult(new ArrayList<>());
    }
}
